package com.guigu.erp.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.erp.mapper.StoragePayMapper;
import com.guigu.erp.pojo.StoragePay;
import com.guigu.erp.service.StoragePayService;
import com.guigu.erp.utils.PageUtils;
import com.guigu.erp.vo.StoragePayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StoragePayServiceImpl extends ServiceImpl<StoragePayMapper, StoragePay>
    implements StoragePayService {

    @Autowired
    private StoragePayMapper storagePayMapper;

    @Override
    public String getMaxDesignId() {
        StoragePay storagePay = storagePayMapper.queryMaxModule();
        if(storagePay==null){
            return null;
        }
        String payId = storagePay.getPayId();
        return payId;
    }

    @Override
    public PageUtils<StoragePay> queryPay(StoragePayVo vo, Integer pageNo, Integer pageSize) {
        //封装查询条件
        QueryWrapper<StoragePay> wrapper = new QueryWrapper<>();
        if(vo!=null){
            if(!StringUtils.isEmpty(vo.getSearch_reason())){
                wrapper.eq("REASON",vo.getSearch_reason());
            }
            if(!StringUtils.isEmpty(vo.getSearch_time1())){
                wrapper.ge("",vo.getSearch_time1());
            }
            if(!StringUtils.isEmpty(vo.getSearch_time2())){
                wrapper.le("",vo.getSearch_time2());
            }
        }
        wrapper.eq("CHECK_TAG","S001-1");
        wrapper.eq("STORE_TAG","K002-1");
        PageHelper.startPage(pageNo,pageSize);
        List<StoragePay> list = this.list(wrapper);
        PageInfo<StoragePay> pageInfo = new PageInfo<>(list);
        PageUtils<StoragePay> pageUtils = new PageUtils<>();
        pageUtils.setTotal(pageInfo.getTotal());
        pageUtils.setRows(pageInfo.getList());
        return pageUtils;
    }
}
